package com.flainsky.nirvanaplayer.globe;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import com.flainsky.nirvanaplayer.R;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class CheckDevice {
	public static boolean checkNetWorkStatus(Context context){
		boolean result;
		ConnectivityManager cm=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netinfo = cm.getActiveNetworkInfo();
		String type = context.getString(R.string.net_type)+netinfo.getTypeName();
		ToastMaker.showToastLong(context, type);
		if(netinfo !=null && netinfo.isConnected()) 
		{
			result=true;
		}
		else
		{
			result=false;
		}
		return result;
	}
	public static boolean checkURL(Context context,String url){
		boolean value=false;
		try {
			HttpURLConnection conn=(HttpURLConnection)new URL(url).openConnection();
			int code=conn.getResponseCode();
			System.out.println(">>>>>>>>>>>>>>>> "+code+" <<<<<<<<<<<<<<<<<<");
			if(code!=200){
				ToastMaker.showToastLong(context, R.string.connect_wlan);
				value=false;
			}else{
				ToastMaker.showToastLong(context, R.string.disconnect_wlan);
				value=true;
			}
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return value;
	}
	public static boolean isSdcardExist() 
	{
		if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
